// pages/ckfwyy/index.js
import {
    formatTime
} from '../../utils/util'
const curDay = new Date()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        curData: [{
            projectName: '中药洗头',
            count: 5,
            residue: 1,
            status: '1'
        }, {
            projectName: '中药泡脚',
            count: 5,
            residue: 1,
            status: '0'
        }, {
            projectName: '满月发汗',
            count: 5,
            residue: 1,
            status: '1'
        }],
        visible: false,
        orderTime: '--',
        pushType: ['消息推送', '微信推送'],
        curPush: '消息推送',
        visibleTime: false,
        minDate: new Date().getTime(),
        maxDate: new Date(curDay.getFullYear(), curDay.getMonth() + 1, 31).getTime(),
        currentDate: new Date(curDay.getFullYear(), curDay.getMonth(), curDay.getDay() + 5, 10, 30).getTime(),
        filter(type, options) {
            if (type === 'minute') {
                return options.filter((option) => option % 5 === 0);
            }
            return options;
        },
    },

    changePushType(e) {
        const {
            type
        } = e.currentTarget.dataset
        this.setData({
            curPush: type
        })
    },

    // 选择时间
    selectTime() {
        this.setData({
            visibleTime: !this.data.visibleTime
        })
        console.log(this.data.visibleTime)
    },

    // 确认
    onConfrimOrder() {
        const {
            orderTime,
            curPush
        } = this.data
        console.log(orderTime,
            curPush)
    },
    // 取消
    onCancelOrder() {
        this.setData({
            visible: false
        })
    },

    onInput(event) {
        console.log(event.detail)
        this.setData({
            orderTime: formatTime(new Date(event.detail)),
        });
    },

    // 动态修改页面标题
    dynamicStateTitle: function (name) {
        wx.setNavigationBarTitle({
            title: name
        })
    },

    confirmTime() {
        this.setData({
            visibleTime: false,
            orderTime: formatTime(new Date(this.data.currentDate))
        })
    },

    // 点击预约
    onReservation(e) {
        const {
            status,
            id
        } = e.currentTarget.dataset
        console.log('====')
        if (status === '0') return;
        this.setData({
            visible: true
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        if (options && options.name) {
            this.dynamicStateTitle(options.name)
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})